<template>
<div class="offline views-container">
    <div class="wlm-form">
        <div class="wlm-form-content">
            <div class="member-header flex-row flex-align-c ">
                <img :src="$route.query.avatarUrl" alt="" class="logo">
                <span class="member-name">{{$route.query.nickName}}</span>
                <div class="line"></div>
                <div class="member-offline-num">
                  <span v-if="!is_move_protect">
                    <span>{{team_diy=='1'?'下线':'客户'}}总数</span> <span class="num">{{$route.query.xx_num}}</span>，
                  </span>
                  {{team_diy=='1'?'其中下级分销商':'销售'}}总数<span class="num">{{$route.query.xjfxs_num}}</span></div>
            </div>
        </div>
    </div>
    <div class="wlm-form">
        <div class="wlm-table">
            <div class="wlm-table-header">
                <!-- <div style="margin:10px 0 20px 4px;">人数： <span style="margin-right:10px;" class="orders-blue">11人</span> 分销商人数：<span class="orders-blue">{{formFormatData.formData.sold_num}}人</span></div> -->
                <el-form :model="tableFormatData.userTable.files" size="small" label-width="73px" class="retail-form" label-position="right">
                    <el-form-item label="查看下线：">
                        <el-select v-model="tableFormatData.userTable.files.type" placeholder="请选择">
                            <el-option v-for="item in [{lable:'全部',value:'0'},{lable:'普通',value:'1'},{lable:'分销商',value:'2'}]" :key="item.value" :label="item.lable" :value="item.value">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="" class="filter-btns">
                        <el-button type="primary" @click="filesSerch">筛选</el-button>
                        <el-button type="text" @click="filesEmpty">清空筛选条件</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <div class="wlm-table-content">
              <!-- <div class="flex-row" style="padding: 10px 0 20px 10px;">
                <el-radio-group v-model="radio">
                  <el-radio :label="3">全部</el-radio>
                  <el-radio :label="6">分销商</el-radio>
                </el-radio-group>
              </div> -->
                <el-tabs v-if="team_diy=='1'" v-model="tableFormatData.userTable.files.level" type="card" @tab-click="filesSerch">
                    <el-tab-pane label="一级下线" name="1"></el-tab-pane>
                    <el-tab-pane label="二级下线" name="2" v-if="commission_level==2||commission_level==3"></el-tab-pane>
                    <el-tab-pane label="三级下线" name="3" v-if="commission_level==3"></el-tab-pane>
                </el-tabs>
                <el-tabs v-if="team_diy=='2'" v-model="tableFormatData.userTable.files.types" type="card" @tab-click="filesSerch">
                    <el-tab-pane v-if="!is_move_protect" label="客户" name="2"></el-tab-pane>
                    <el-tab-pane label="销售" name="1"></el-tab-pane>
                </el-tabs>
                <el-table :ref="tableFormatData.userTable.key" :data="tableFormatData.userTable.tableData" @selection-change="handleSelectionChange" style="width: 100%">
                    <el-table-column prop="date" label="用户">
                        <template slot-scope="scope">
                          <div class="wlm-table-logos flex-row">
                            <img class="logo" :src="scope.row.avatarUrl">
                            <div class="flex-col" style="margin-left: 10px;">
                                <p class="ellipsis" style="width:200px;">{{scope.row.nickName}}</p>
                                <el-tooltip class="item" effect="dark" :content="sourceType[`${scope.row.source}`]" placement="top">
                                    <img height="20" width="20" :src="sourceImg[`${scope.row.source || '--'}`]" alt="">
                                </el-tooltip>
                            </div>
                        </div>
                        </template>
                    </el-table-column>
                    <el-table-column  label="分销商等级" min-width="60">
                        <template slot-scope="scope">
                            <span>{{scope.row.dealer_leave_leave_title||'-'}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column  label="手机号/姓名">
                        <template slot-scope="scope">
                            <p>{{scope.row.mobile!='0'?scope.row.mobile:'-'}}</p>
                            <p>{{scope.row.dealer_user_real_name}}</p>
                        </template>
                    </el-table-column>
                    <el-table-column  label="成为时间">
                        <template slot-scope="scope">
                            <span>{{scope.row.dealer_referee_create_time*1000 | parseTime('{y}-{m}-{d} {h}:{i}:{s}')}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column  label="保护到期时间">
                        <template slot-scope="scope">
                            <span>{{scope.row.protect_time||'-'}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="操作">
                        <template slot-scope="scope">
                            <div class="operation-group">
                                <el-button @click="changeTableItem({user_id:scope.row.user_id,dealer_id:'0'},tableFormatData.userTable.change.stop)" v-if="scope.row.level==4" class="wlm-text"  type="text">解绑</el-button>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="pagination-content flex-row flex-justify-e flex-align-c">
                    <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.userTable.pagination.page" :page-sizes="tableFormatData.userTable.pagination.pagesizes" :page-size.sync="tableFormatData.userTable.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.userTable.pagination.total : 0">
                    </el-pagination>
                </div>
            </div>
        </div>
    </div>
</div>
</template>

<script>
import {
  keyVercodeDestroy
} from '@/api/application'
import {
  getTeamData,
  LeaveList
} from '@/api/distribution'
import {
  editReferee
} from '@/api/user'
import mixins from '@/mixins/mixins'
import exceldown from '@/directive/exceldown'
import ExportFileIn from '@/components/ExportFileIn/index'
export default {
  mixins: [mixins.getters('Table')],
  name: 'Offline',
  components: {
    ExportFileIn
  },
  computed: {
  },
  directives: {
    exceldown
  },
  created() {
    LeaveList().then((response) => {
      const {
        data: {
          data: msgData = []
        }
      } = response
      this.commission_level = msgData.commission_level
      this.team_diy = msgData.team_diy
      this.is_move_protect = msgData.is_move_protect
    })
  },
  data() {
    return {
      commission_level: '',
      is_move_protect: false,
      team_diy: '',
      visible: false,
      history: {
        kammi_id: '',
        user_id: '',
        vercode: '',
        explain: '',
        range: 'one'
      },
      dialogIndex: -1,
      tableFormatData: {
        current: 'userTable',
        userTable: {
          key: 'userTable',
          api: {
            getList: getTeamData,
            delList: keyVercodeDestroy
          },
          tableData: [],
          files: {
            level: '1',
            types: '1',
            type: '0',
            ids: [],
            checkall: '0',
            Recycle: '1'
          },
          change: {
            stop: {
              name: '停止',
              key: 'stop',
              api: editReferee
            }
          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      }
    }
  },
  methods: {
    changeTableCallBack({ event, params: { response: { data: { data: { dealer_count, user_count } } } } }) {
      if (event === 'getList') {
        // if (this.team_diy === '1') {
        //   this.tableFormatData.userTable.files.types = 0
        // }
        // console.log(user_count, 'user_count')
        // console.log(dealer_count, 'dealer_count')
      }
    }
  },
  destroyed() {
    console.log(this.$store.commit('SET_BREADCRUMB_TITLE', ''), '页面销毁')
  }
}
</script>

<style lang="scss" scoped>
.offline {
    .member-header {
        padding-left: 20px;
        height: 40px;
    }

    .member-name {
        display: block;
        height: 40px;
        line-height: 40px;
        margin: 0 50px 0 10px;
        font-size: 14px;
        color: #333;
    }

    .line {
        height: 40px;
        padding: 5px 0;
        background-color: #dddee1;
        background-clip: content-box;
        width: 1px;
    }

    .member-offline-num {
        float: left;
        margin-left: 50px;
        height: 40px;
        line-height: 36px;
        font-size: 14px;
        color: #333;
    }

    .member-offline-num .num {
        font-size: 24px;
        font-weight: 600;
    }
}
</style>
